//
//  HMHomeRetweetView.swift
//  HMSlender
//
//  Created by 赵少朋赵少朋 on 2017/2/7.
//  Copyright © 2017年 ITheima. All rights reserved.
//

import UIKit

class HMHomeRetweetView: UIView {

    var contentLabelBottomConstraint:Constraint?
    var statusModel: HMStatusViewModel? {
    
        didSet {
            //赋值
            contentLabel.text = statusModel?.homeModle?.retweeted_status?.text
            //卸掉约束
            contentLabelBottomConstraint?.uninstall()
            if let picurls = statusModel?.homeModle?.retweeted_status?.pic_urls, picurls.count > 0 {
                //转发微博中有图片
                pictureView.pictureUrls = picurls
                snp_makeConstraints(closure: { (make) in
                    contentLabelBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                })
                pictureView.isHidden = false
            } else {
                // 没有图片
                snp_makeConstraints(closure: { (make) in
                    contentLabelBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
                pictureView.isHidden = true
            }
        }
    }
    
    
     override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.init(r: 235, g: 235, b: 235, alpha: 1)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() -> Void {
        //微博内容
        addSubview(contentLabel)
        /// 图片
        addSubview(pictureView)
        //约束
        contentLabel.snp_makeConstraints { (make) in
            make.left.top.equalTo(self).offset(10)
            make.right.equalTo(self).offset(-10)
//            contentLabelBottomConstraint = make.bottom.equalTo(self).offset(-10).constraint
        }
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
            make.left.equalTo(self).offset(10)
//            make.bottom.equalTo(self).offset(-10)
        }
        
        snp_makeConstraints { (make) in
            contentLabelBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }
    }
    
    /// 微博内容
    private lazy var contentLabel:UILabel = {
    
        let lab = UILabel(textSize: midTextFont, color: UIColor.black)
        lab.numberOfLines = 0
        
        return lab
    }()
    
    /// 微博图片
    private lazy var pictureView:HMStatusPictureView = HMStatusPictureView()
}
